package com.multimedia.scala.euler
/*
The sequence 1, 1, 1, 3, 5, 9, 17, 31, 57, 105, 193, 355, 653, 1201 ...
is defined by T1 = T2 = T3 = 1 and Tn = Tn-1 + Tn-2 + Tn-3.

It can be shown that 27 does not divide any terms of this sequence.
In fact, 27 is the first odd number with this property.

Find the 124th odd number that does not divide any terms of the above sequence.
 */
object Asd225 {
  def main(args : Array[String]) : Unit = {
    var res = oddList(6723)
    //res = res.filter(isSimple).filter(odd)
    //var res = (1 to 100).map(27*_)
    //res = res.filter(odd)
    var time = java.lang.System.currentTimeMillis()
    var iter = 0
    println("len = "+res.length)
    tribanacci().takeWhile(_<BigInt(10).pow(10000)).foreach(x => {
    	res = res.filter(x%_!=0)
    })
    var i = 0
    res.foreach(x => {println(i + ":" + x); i+=1})
    var timeTotal = java.lang.System.currentTimeMillis() - time
    println("time = " + timeTotal+"; iterations = " + iter)
  }

  def odd(a: Int): Boolean = a%2==1
  
  def isSimple(x: Int): Boolean = {
      for (i <- 2 to x-1)
        if (x%i==0) return false
      return true
  }
  
  def oddList(max: Int): scala.collection.mutable.ListBuffer[Int] = {
      var rez = scala.collection.mutable.ListBuffer[Int]()
      for (i <- 1 to max/2)
          rez.append(i*2+1)
      rez
  }

  def tribanacci(a: BigInt = 1, b: BigInt = 1, c: BigInt = 1): Stream[BigInt] = {
    Stream.cons(a, tribanacci(b, c, a + b + c))
  }
    
}
